﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Lipesin.BuildUpdateLaunch
{
	public class Config
	{
		private string _content;
		public string SourcePath { get; set; }
		public string FileRegEx { get; set; }

		public Config()
			: this(null as Stream)
		{ }

		delegate string dReader(Stream stream);
		public Config(Stream stream)
			: this(
				(
					(dReader)
					(
						(Stream s) =>
						{
							using (Stream embed = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Lipesin.BuildUpdateLaunch.Embedded.config.txt"))
							using (StreamReader reader = new StreamReader(stream == null ? embed : stream))
								return reader.ReadToEnd();
						}
					)
				)(stream))
		{ }

		public Config(string content)
		{
			_content = content;
			string[] lines = _content.Split(new string[] { "\r\n" }, StringSplitOptions.None);
			SourcePath = lines[0];
			FileRegEx = lines[1];
		}

		public void Write(Stream stream)
		{
			using (StreamWriter writer = new StreamWriter(stream))
				writer.Write(_content);
		}
	}
}
